<?php

class Db_Tables_BjmCategories extends Zend_Db_Table
{
    protected $_name = 'bjm_categories';
	
	function GetCid($key)
	{
		$cid = 0;
		
		if($key)
		{
			$row = $this->fetchRow("cname='".$key."'");
			
			if($row)
			{
				$cid = $row['cid'];
			}else{
				$nrow = $this->createRow();
				$nrow->cname = $key;
				$cid = $nrow->save();
			}
		}
		
		return $cid;
	}
	
	function GetCategories()
	{
		$result = array();
		
		$rows = $this->fetchAll();
		
		if($rows)
		{
			foreach($rows as $row)
			{
				$result[$row['cid']] = $row['cname'];
			}
		}
		
		return $result;
	}
}